<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/m/include/init_mobile.jsp" %>
<%
	
	boolean test = false;
	
	if ("110.35.116.132".equals(request.getRemoteAddr())) {
		test = true;
	}
	if ("0:0:0:0:0:0:0:1".equals(request.getRemoteAddr())) {
		test = true;
	}
	if ("a".equals(session_user_id)) {
		test = true;
	}
	
	String book_code		= StringUtil.nvl(request.getParameter("book_code"));

	HashMap infos = new HashMap();
	infos.put("book_code", book_code);
	
	StoreDAO dao = new StoreDAO();
	HashList bookInfo 		= dao.selectBookInfo(infos);
	
	dao.updateBookHitCount(infos);
%>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
	<title><%= HOME_NAME %></title>
	<%@ include file="/m/include/cssnjs.jsp"  %>
	<link rel="stylesheet" href="/css/jquery.mobile-1.4.2.min.css"/>
	
	
	<script type="text/javascript">

	$(document).ready(function() {
		
		$('#header-nav li:nth-child(3)').addClass('on');
		
		$('.ui-btn').on('touchstart', function() {
			$(this).addClass('ui-btn-active');
		});
		
		
		$('div.rate span').mouseover(function(){
			var curTitle = $(this).attr('title');
			$('div.rate span').each(function(){
				if ($(this).attr('title') <= curTitle) {
					$(this).text('★');
				} else {
					$(this).text('☆');
				}
			});
		});
		
		$('textarea').on('keyup', function(){
			this.style.height = "1px";
			this.style.height = (20+this.scrollHeight)+"px";
		});
		
		$('.modal-content div.btn').on('touchstart', function() {
			$(this).addClass('modal-btn-active');
		});
		
		$('#review_list').load('./bookDetail.app?book_code=<%=book_code%>&job_type=review', '', function() {});

	});


	function fnPurchaseBook() {
		if (<%=isLogin%> == false) {
			cfShowModalConfirm('로그인하시겠습니까?');
			return false;
		}
		return true;
	}
	
	function fnGoPurchaseBook() {
		document.location.href = "http://www.qbooks.co.kr";
	}
	
	function fnConfirmYes() {
		document.location.href = "../member/login.jsp?next_url=" + document.location.href;
	}

	
	function btnReviewSave() 
	{
		if (<%=isLogin%> == false) {
			cfConfirmModal('로그인하시겠습니까?');
			$('.ui-btn').removeClass('ui-btn-active');
			return false;
		}
		
		var intRate = 0;
		$('div.rate span').each(function(){
			if ($(this).text() == '★') {
				if (this.title > intRate) {
					intRate = this.title;
				}
			}
		});

		if (intRate == 0) {
			cfAlertModal('평점을 선택하세요');
			$('.ui-btn').removeClass('ui-btn-active');
			return false;
		} 
		

		$.ajax({
			url: '/home/store/reviewSave.do',
			type: "POST",
		    dataType: 'json',
		    data:{ 
		    	book_code:'<%=book_code%>',
		    	rate:intRate, 
		    	review_info:$('#review_info').val() 
		    },
		    error: function(data, status, err){
		    	cfAlertModal(err);
		    },
			success: function(data){
				if (data.result) {
					$('#reviewForm').remove();
					$('#review_message').show();
					$('#review_list').load('./bookDetail.app?book_code=<%=book_code%>&job_type=review', '', function() {});
				} else {
					cfAlertModal(data.message);
				}
		    }
		});
		
		$('.ui-btn').removeClass('ui-btn-active');
	}
	
	
	

	//무료 다운로드
	function fnDownloadFree() 
	{
	<%	if (os.equals("android")) {	%>
			window.android.downloadFree('<%=book_code%>');
	<%	} else if (os.equals("ios")) {	%>
			window.location="jscall:downloadFree:<%=book_code%>";
	<%	} else {	%>
			alert("앱에서 다운로드 가능합니다.");
			return;
	<%	}	%>	
		
		$('#download_button').hide();
		$('#download').show();
	}
	
	//샘플 다운로드 
	function fnDownloadSample() {
	<%	if (os.equals("android")) {	%>
			window.android.downloadPreview('<%=book_code%>');
	<%	} else if (os.equals("ios")) {	%>
			window.location="jscall:downloadPreview:<%=book_code%>";
	<%	} else {	%>
			alert("앱에서 다운로드 가능합니다.");
	<%	}	%>
	}
	
	
	//다운로드 취소시 또는 열기
	function fnCancelDownload() {
		if ($('#cancel_button').text() == '취소') {
		<%	if (os.equals("android")) {	%>
				window.android.cancelDownloadFree('<%=book_code%>');
		<%	} else if (os.equals("ios")) {	%>
				window.location="jscall:cancelDownloadFree:<%=book_code%>";
		<%	} %>
		} else if ($('#cancel_button').text() == '열기') {
		<%	if (os.equals("android")) {	%>
				window.android.openBook('<%=book_code%>');
		<%	} else if (os.equals("ios")) {	%>
				window.location="jscall:openBook:<%=book_code%>";
		<%	} %>
		}
		
		//샘플 다운로드 취소시
	    //window.android.cancelDownloadPreview([book_code]);
	}
	
	//앱에서 콜백
	function callJS(progress) {
		if (progress == 100) {	//다운로드완료
			$('#progressbar').val(progress);
			$('#cancel_button').hide();
			$('#download_status').text('설치 중...');
		} else if (progress == 200){	//설치완료
			$('#download_status').text('설치완료');
			$('#cancel_button').text('열기').show();
		} else if (progress == 900) {	//취소완료
			$('#download_button').show();
			$('#download').hide();
			$('#progressbar').val('0');
			$('#download_status').text('다운로드 중...0%');
		} else {
			$('#progressbar').val(progress);
			$('#download_status').text('다운로드 중...' + progress+'%');
		}
	}

	</script>
</head>
<body>
 	<div id="wrap" class="ui-page-theme-a">
		<%@ include file="/m/include/header.jsp"  %>
        <div class="content">
        	
	        <div>
		        <div style="float:left; width:35%">
		        	<img src="<%= bookInfo.get("book_image_url",0) %>" style="width:100%"/>
		        </div>
	        	<div style="float:left; width:65%;">
	        		<div class="book_title"><%= bookInfo.get("book_name", 0) %></div>
	        		<div class="book_info">
		        		<p><%= bookInfo.get("author_name",0) %> 저</p>
						<p><%= bookInfo.get("publisher_name",0) %>, <%= StringUtil.toDate(bookInfo.get("publish_dt",0),".") %></p>
						<p>총 <%= StringUtil.toPrice(bookInfo.get("page_count",0)) %> page, <%= bookInfo.get("file_size", 0) %></p>
				<%	if (!test && "0".equals(bookInfo.get("book_type",0))) { %>
						<div id="download">
							<progress id="progressbar" value="0" max="100"></progress>
							<div id="download_status" >다운로드 중...0%</div>
							<div id="cancel_button" onclick="fnCancelDownload()">취소</div>
						</div>
						<div id="download_button" class="ui-btn ui-input-btn  ui-corner-all ui-shadow">무료 다운로드<input type="button" alt="다운로드" value="다운로드" onclick="fnDownloadFree()"/></div>
				<%	} else { %>
				<%		if (os.equals("android")) {	%>
							<div class="ui-btn ui-input-btn ui-btn-active ui-corner-all ui-shadow">
								<a href="http://www.qbooks.co.kr" target="_blank"><%= bookInfo.getPrice("price",0) %>원 구매하기</a>
							</div>
				<%		} else { %>
							<form method="post" id="LGD_PAYINFO" action="../LGU_SmartXPay/payreq_crossplatform.jsp" onsubmit="return fnPurchaseBook()">
							<input type="hidden" name="os" value="<%=os %>"/>
						    <input type="text" name="CST_MID" value="X_qbooks"/><!-- 상점아이디(t를 제외한 아이디) -->
						    <input type="text" name="CST_PLATFORM" value="test"/><!-- 서비스,테스트 -->
						    <input type="text" name="LGD_BUYER" value="<%= session_user_name %>"/><!-- 구매자이름 -->
						    <input type="text" name="LGD_PRODUCTINFO" value="<%= bookInfo.get("book_name", 0) %>"/><!-- 상품정보 -->
						    <input type="text" name="LGD_AMOUNT" value="3000"/><!-- 결제금액 -->
						    <input type="text" name="LGD_BUYEREMAIL" value="<%= session_user_id %>"/><!-- 구매자 이메일 -->
						    <input type="text" name="LGD_OID" value="<%= CommonUtil.getOrderNo()%>"/><!-- 주문번호 -->
						    <input type="text" name="LGD_TIMESTAMP" value="<%= CommonUtil.getTimeStamp()%>"/><!-- 타임스탬프 -->
						    <select name="LGD_CUSTOM_FIRSTPAY">
								<option value="SC0010">신용카드</option>
								<option value="SC0030">계좌이체</option>
								<option value="SC0040">무통장입금</option>
								<option value="SC0060">휴대폰</option>
								<option value="SC0070">유선전화결제</option>
								<option value="SC0090">OK캐쉬백</option>
								<option value="SC0111">문화상품권</option>				
								<option value="SC0112">게임문화상품권</option>				
							</select><!-- 초기결제수단 -->
						    
							<%-- <p><strong>판매가 :</strong> <span class="price"><%= bookInfo.getPrice("price",0) %></span>원</p> --%>
							<div class="ui-btn ui-input-btn ui-btn-active ui-corner-all ui-shadow">
								<%= bookInfo.getPrice("price",0) %>원 구매하기
								<input type="submit" alt="구매하기" value="구매하기"/>
							</div>
						    </form>
				<%		} %>
				<%	} %>
				
				<%	if (!"".equals(bookInfo.get("preview_book_url",0))) { %>
						<div class="ui-btn ui-input-btn ui-corner-all ui-shadow">샘플 다운로드 <span class="remark">(<%=bookInfo.get("preview_file_size",0) %>)</span><input type="button" alt="다운로드" value="다운로드" onclick="fnDownloadPreview()"/></div>
				<%	} %>
					</div>
				</div>
			</div>
			
			<div class="clear">

			</div>
			
			<div class="item_title mt30"><h3>설명</h3></div>
			<div class="item_desc"><%= StringUtil.toHTML(bookInfo.get("intro", 0)) %></div>

	<%	if (!"".equals(bookInfo.get("index_info", 0))) { %>
			<div class="item_title"><h3>목차</h3></div>
			<div class="item_desc"><%= StringUtil.toHTML(bookInfo.get("index_info", 0)) %></div>
	<%	} %>

	<%	if (!"".equals(bookInfo.get("author_info", 0))) { %>
			<div class="item_title"><h3>저자 정보</h3></div>
			<div class="item_desc"><%= StringUtil.toHTML(bookInfo.get("author_info", 0)) %></div>
	<%	} %>
			
	
		</div>
        
		<%@ include file="/m/include/footer.jsp"  %>		
        
	</div>
	
	
</body>
</html>


